<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<!-- 引入easyui 的主题样式  和  easyui 提供的图标样式 -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/icon.css" />
<!-- 引入jquery 和  easyui.js   中文设置js-->
<script type="text/javascript"
	src="${pageContext.request.contextPath}\js\jquery-1.9.1.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
</head>
<script type="text/javascript">
$(function(){
	$.extend($.fn.validatebox.defaults.rules, {	  
	    onlyNum:{
	        validator:function(value,param){
	        	var reg = /^\d+(\.\d{2})?$/;
	            return reg.test(value);
	        },
	        message:  '只能输入整数或小数，保留两位小数！'
	    }
	});
	
	
	$('#dg').datagrid({    
	    url:'getDis',    
	    columns:[[
	        {field : 'ck',width : 100,checkbox : true},     
	        {field:'disId',title:'配送间价格编号',width:100,align:'center'},    
	        {field:'disFirstKilogramPrice',title:'首公斤价格（元）',width:100,align:'center'},    
	        {field:'disNextKilogramPrice',title:'次公斤价格（元）',width:100,align:'center'},   
	        {field:'disFirstCubicPrice',title:'首立方价格（元）',width:100,align:'center'},   
	        {field:'disNextCubicPrice',title:'次立方价格（元）',width:100,align:'center'},   	       
	        {field:'disState',title:'状态',width:80,align:'center'}, 
	        {field:'dpNamef',title:'发货地',width:100,align:'center'}, 
	        {field:'dpNames',title:'目的地',width:100,align:'center'},   	         
	        {field:'otName',title:'订单类别',width:90,align:'center'}, 
	        {field:'disRemarks',title:'备注',width:100},
	    ]]  ,
	rownumbers : true,
	pagePosition : 'bottom',
	pagination : true,
	pageSize : 10,
	pageList : [ 5, 10, 15 ],
	toolbar: [{
		iconCls: 'icon-add',
		text:"增加配送间价格",
		handler: function(){
			$("#adddis").window('open');
		}
	},'-',{
		iconCls: 'icon-edit',
		text:"调整配送间价格",
		handler: function(){
			var dis = $("#dg").datagrid("getChecked");
			if (dis.length==1) {
			$('#updatedis').window("open");
				$('#disId2').textbox({    
				    value: dis[0].disId,     
				})
				$('#disFirstKilogramPrice2').textbox({    
				    value: dis[0].disFirstKilogramPrice,     
				})
				$('#disNextKilogramPrice2').textbox({    
				    value: dis[0].disNextKilogramPrice,     
				})
				$('#disFirstCubicPrice2').textbox({    
				    value: dis[0].disFirstCubicPrice,     
				})
				$('#disNextCubicPrice2').textbox({    
				    value: dis[0].disNextCubicPrice,     
				})
				$('#disRemarks2').textbox({    
				    value: dis[0].disRemarks,     
				})
				$('#disState2').textbox({    
				    value: dis[0].disState,     
				})
				$('#dpNamef2').combobox({
					value: dis[0].dpNamef,  
				})
				$('#dpNames2').combobox({
					value: dis[0].dpNames,  
				})
				$('#otName2').combobox({
					value: dis[0].otName,  
				})
			}else{
				$.messager.alert('警告','请选择一行！');  
			}
		}
	}]

	});
	
//增加窗口
$('#adddis').window({
	width : 600,
	height : 450,
	modal : true,
	title : "增加",
	collapsible : false,
	minimizable : false,
	maximizable : false,
	closable : false,
	closed : true
});

$('#disFirstKilogramPrice1').textbox({
	buttonText : '首公斤价格',
	buttonAlign:"left",
	required:true,
	validType:'onlyNum'
});

$('#disNextKilogramPrice1').textbox({
	buttonText : '次公斤价格',
	buttonAlign:"left",
	required:true,
	validType:'onlyNum'
});

$('#disFirstCubicPrice1').textbox({
	buttonText : '首立方价格',
	buttonAlign:"left",
	required:true,
	validType:'onlyNum'
});

$('#disNextCubicPrice1').textbox({
	buttonText : '次立方价格',
	buttonAlign:"left",
	required:true,
	validType:'onlyNum'
});

$('#disRemarks1').textbox({
	buttonText : '备注',
	buttonAlign:"left",
	multiline:true
});
$('#disState1').textbox({
	buttonText : '是否审核',
	buttonAlign:"left",
	value:"未审核",
	readonly:true
});

//发货地
$('#dpNamef1').combobox({    
    url:'findDp',    
    valueField:'dpId',    
    textField:'dpName',
    buttonText : '发货地',
    buttonAlign:"left",
    editable:false,
});
//目的地
$('#dpNames1').combobox({    
    url:'findDp',    
    valueField:'dpId',    
    textField:'dpName',
    buttonText : '目的地',
    buttonAlign:"left",
    editable:false,
}); 
//订单类别
$('#otName1').combobox({    
    url:'findOt',    
    valueField:'otId',    
    textField:'otName',
    buttonText : '订单类别',
    buttonAlign:"left",
    editable:false,
    onHidePanel:function(){
    	var dpNamef = $('#dpNamef1').combobox('getValue');
    	var dpNames = $('#dpNames1').combobox('getValue');
    	var otName = $('#otName1').combobox('getValue');		
        $.ajax({		    
        	type:'post',
        	url:'validateAddDis',
        	data:{'dpIdf' : dpNamef,
    			'dpIds' : dpNames,
    			'otId' : otName},
        	dataType:'text',
        	success:function(data){
        		 
        		if (data==1) {
        			$.messager.alert('警告','该配送间已存在！');  		
    			}else{
    				$.messager.alert('消息','该配送间价格可添加！');  
    		}
       	}
}); 
	
    }
})
//增加确定按钮
$('#adddisyes').linkbutton({
	onClick : function() {
		var disFirstKilogramPrice = $('#disFirstKilogramPrice1').val();
		var disNextKilogramPrice = $('#disNextKilogramPrice1').val();
		var disFirstCubicPrice = $('#disFirstCubicPrice1').val();
		var disNextCubicPrice = $('#disNextCubicPrice1').val();
		var disRemarks = $('#disRemarks1').val();
		var disState = $('#disState1').val();
		var dpNamef = $('#dpNamef1').combobox('getValue');
		var dpNames = $('#dpNames1').combobox('getValue');
		var otName = $('#otName1').combobox('getValue');
	
		$.ajax({
			url : 'insertDIS',
			type : 'post',
			data : {
				'disFirstKilogramPrice':disFirstKilogramPrice,
				'disNextKilogramPrice':disNextKilogramPrice,
				'disFirstCubicPrice' : disFirstCubicPrice,
				'disNextCubicPrice' : disNextCubicPrice,
				'disRemarks' : disRemarks,
				'disState' : disState,
				'dpIdf' : dpNamef,
				'dpIds' : dpNames,
				'otId' : otName,
			},
			detaType : 'text',
			success : function(data) {
			
				if (data == 1) {
					
					$.messager.confirm('确认','您确认提交审核吗？',function(r){    
					    if (r){    
					        alert('提交审核成功');    
					    }    
					    $("#dg").datagrid('reload');
					});  

				} else {
					$.messager.show({
						title : '信息提示',
						msg : '增加失败',
						timeout : 1000,
						showType : 'slide'
					});
				}
			}
		});
		$('#adddis').window("close");
	}
});
//增加取消
$('#adddisno').linkbutton({
	onClick : function() {
		$('#adddis').window("close");
	}
});



//修改窗口
$('#updatedis').window({
	width : 600,
	height : 500,
	modal : true,
	title : "修改",
	collapsible : false,
	minimizable : false,
	maximizable : false,
	closable : false,
	closed : true
});

$('#disId2').textbox({
	buttonText : '配送间价格编号',
	buttonAlign:"left",
	readonly:true
});
$('#disFirstKilogramPrice2').textbox({
	buttonText : '首公斤价格',
	buttonAlign:"left",
	required:true,
	validType:'onlyNum'
});

$('#disNextKilogramPrice2').textbox({
	buttonText : '次公斤价格',
	buttonAlign:"left",
	required:true,
	validType:'onlyNum'
});

$('#disFirstCubicPrice2').textbox({
	buttonText : '首立方价格',
	buttonAlign:"left",
	required:true,
	validType:'onlyNum'
});

$('#disNextCubicPrice2').textbox({
	buttonText : '次立方价格',
	buttonAlign:"left",
	required:true,
	validType:'onlyNum'
});

$('#disRemarks2').textbox({
	buttonText : '备注',
	buttonAlign:"left",
	multiline:true
});
$('#disState2').textbox({
	buttonText : '是否审核',
	buttonAlign:"left",
	value:"未审核",
	readonly:true
});

//发货地
$('#dpNamef2').combobox({    
    url:'findDp',    
    valueField:'dpId',    
    textField:'dpName',
    buttonText : '发货地',
    buttonAlign:"left",
    editable:false,
    readonly:true
});
//目的地
$('#dpNames2').combobox({    
    url:'findDp',    
    valueField:'dpId',    
    textField:'dpName',
    buttonText : '目的地',
    buttonAlign:"left",
    editable:false,
    readonly:true
}); 
//订单类别
$('#otName2').combobox({    
    url:'findOt',    
    valueField:'otId',    
    textField:'otName',
    buttonText : '订单类别',
    buttonAlign:"left",
    editable:false,
    readonly:true
}); 
//修改确定按钮
$('#updatedisyes').linkbutton({
	onClick : function() {
		$('#updatedis').window("close");
		
		$.ajax({
			url : 'updateDIS',
			type : 'post',
			data : {
				'disId':$("#disId2").val(),
				'disFirstKilogramPrice' : $("#disFirstKilogramPrice2").val(),
				'disNextKilogramPrice' : $("#disNextKilogramPrice2").val(),
				'disFirstCubicPrice' : $("#disFirstCubicPrice2").val(),
				'disNextCubicPrice' : $("#disNextCubicPrice2").val(),
				'disRemarks' : $("#disRemarks2").val(),
				
			},
			dataType : 'text',
			success : function(data) {
				
				if (data == 1) {
					$("#dg").datagrid('reload');
					$.messager.alert('消息','修改成功');  
				} else {
					$.messager.show({
						title : '信息提示',
						msg : '修改失败',
						timeout : 1000,
						showType : 'slide'
					});
				}

			}
		});
	}
});
//修改取消
$('#updatedisno').linkbutton({
	onClick : function() {
		$('#updatedis').window("close");
		$("#dg").datagrid('uncheckAll')
	}
});



});
</script>
<body>
<table id="dg"></table>

<!-- 增加窗口 -->

	<div id=adddis>
		
<div style="margin-left: 100px; margin-top: 50px">
		
			 <input
				id="disFirstKilogramPrice1" type="text" 
				style="width: 200px; height: 32px">  
				<input
				id="disNextKilogramPrice1" type="text" 
				style="width: 200px; height: 32px"> <br><br>
				 <input id="disFirstCubicPrice1" type="text" 
				style="width: 200px; height: 32px">
				 <input
				id=disNextCubicPrice1 type="text" 
				style="width: 200px; height: 32px"><br><br>
				 
				 <input
				id="disState1" type="text" 
				style="width: 200px; height: 32px">
				<input
				id="dpNamef1" type="text" 
				style="width: 200px; height: 32px"><br><br>
				 <input
				id="dpNames1" type="text" 
				style="width: 200px; height: 32px">
				 
				<input
				id="otName1" type="text" 
				style="width: 200px; height: 32px"> <br><br>
				<input
				id="disRemarks1" type="text" 
				style="width: 400px; height: 100px"><br><br>
				
				 <a id="adddisyes" href="#" iconCls="icon-ok"
				style="width: 90px; height: 32px;margin-left: 100px">确定</a> <a id="adddisno" href="#"
				iconCls="icon-no" style="width: 90px; height: 32px">取消</a>

		</div>
	</div>

<!-- 修改窗口 -->

	<div id="updatedis">
		
<div style="margin-left: 100px; margin-top: 50px">
	<input id="disId2" type="text" name="Distributionrangeprice.drpId"
				style="width: 200px; height: 32px">
			 <input
				id="disFirstKilogramPrice2" type="text" name="Distributionrangeprice.drpFirstKilogramPrice"
				style="width: 200px; height: 32px">  <br><br>
				<input
				id="disNextKilogramPrice2" type="text" name="Distributionrangeprice.drpNextKilogramPrice"
				style="width: 200px; height: 32px"> 
				 <input id="disFirstCubicPrice2" type="text" name="Distributionrangeprice.drpFirstCubicPrice"
				style="width: 200px; height: 32px"><br><br>
				 <input
				id=disNextCubicPrice2 type="text" name="Distributionrangeprice.drpNextCubicPrice"
				style="width: 200px; height: 32px">
				
				 <input
				id="disState2" type="text" name="Ordertype.otId"
				style="width: 200px; height: 32px"><br><br>
				<input
				id="dpNamef2" type="text" name="Deliverypoint.dpId"
				style="width: 200px; height: 32px">
				 <input
				id="dpNames2" type="text" name="Distributionscope.dsId"
				style="width: 200px; height: 32px"><br><br>
				
				<input
				id="otName2" type="text" name="Distributionscope.dsId"
				style="width: 200px; height: 32px"> <br><br>
				
				 <input
				id="disRemarks2" type="text" name="Distributionrangeprice.drpRemarks"
				style="width: 400px; height: 100px">  <br><br>
				
				 <a id="updatedisyes" href="#" iconCls="icon-ok"
				style="width: 90px; height: 32px;margin-left: 100px">确定</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<a id="updatedisno" href="#"
				iconCls="icon-no" style="width: 90px; height: 32px">取消</a>

		</div>
		</div>
		

</body>
</html>